package cn.ztuo.bitrade.controller;

import cn.ztuo.bitrade.service.CesspitRecordService;
import cn.ztuo.bitrade.service.MemberService;
import cn.ztuo.bitrade.service.RelationService;
import cn.ztuo.bitrade.util.MessageResult;

import cn.ztuo.bitrade.vo.RelationVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.math.BigDecimal;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/relation")
public class RelationController extends BaseController  {

    @Autowired
    private RelationService relationService;

    @Autowired
    private CesspitRecordService cesspitRecordService;

    /*
    * 获取当前用户左区算力
    * */
    @RequestMapping("left")
    public MessageResult left(Long id) {
        BigDecimal left = relationService.userLeft(id);
        return success(left);
    }
    /*
     * 获取当前用户右区算力
     * */
    @RequestMapping("right")
    public MessageResult right(Long id) {
        BigDecimal left = relationService.userRight(id);
        return success(left);
    }
    /*
     * 获取当前用户算力值
     * */
    @RequestMapping("record")
    public MessageResult cesspitRecord(long id)
    {
        BigDecimal record = cesspitRecordService.getHashrate(id);
        return success(record);
    }

    /*
     *  统计所有用户的算力综合
     * */
    @RequestMapping("sum")
    public MessageResult sumHashrate()
    {
        String[] sumEarning = cesspitRecordService.sumHashRate();
        return success(sumEarning);
    }

    @RequestMapping("get")
    public MessageResult getHashrate(long id)
    {
        RelationVO relationVO = new RelationVO();
        try
        {

            relationVO.a = relationService.allWeighted();//全网社区算力
            relationVO.b = relationService.weighted(id);//个人社区算力
            relationVO.left = relationService.userLeft(id);
            relationVO.right = relationService.userRight(id);
            relationVO.record = relationVO.b;
            relationVO.sum =relationVO.a.toString();
            relationVO.d =new BigDecimal(cesspitRecordService.sumHashRate()[0]);
            relationVO.e = new BigDecimal("0.00");//全网排名算力
            relationVO.f = new BigDecimal("0.00");
            relationVO.g = new BigDecimal("0.00");
            relationVO.h = new BigDecimal(cesspitRecordService.sumAmount(id)[0]);
            relationVO.i = cesspitRecordService.getHashrate(id);
            relationVO.c = relationVO.d.add(relationVO.a);//全网算力
            relationVO.j = new BigDecimal("0.00");
            relationVO.k = new BigDecimal("0.00");
            return success(relationVO);
        }catch (Exception e)
        {
            e.printStackTrace();
            log.info("----get 出错----",e.getMessage());
            return error("");
        }

    }

}
